/**
 * @author Jjn
 * @since 2021-06-12 10:37
 */
public class Solution_58_1 {
    public int lengthOfLastWord(String s) {
        if (s == null) {
            return 0;
        }
        int length = s.length();
        int end = length - 1;
        int i = end;
        while (i >= 0) {
            char c = s.charAt(i);
            if (!Character.isAlphabetic(c)) {
                i--;
            } else {
                break;
            }
        }
        end = i;
        while (i >= 0) {
            char c = s.charAt(i);
            if (Character.isAlphabetic(c)) {
                i--;
            } else {
                break;
            }
        }
        int start = i;
        return end - start;
    }
    
    public static void main(String[] args) {
        Solution_58_1 solution_58_1 = new Solution_58_1();
        System.out.println(solution_58_1.lengthOfLastWord("1122 aaabbb "));
    }
}
